using System;
using System.Collections.Generic;
using System.Text;
using SP.Parameter;

namespace SP.HwDeferredRS
{
    /// <summary>
    /// A DeferredLighting Fusion
    /// </summary>
    public class DeferredLightingFusion : AbstractFusion
    {
        public DeferredLightingFusion()
        {
            AddPreprocessor(new Preprocessor("DEFERREDLIGHTING_SHADOWS", 0, 1, 1, "Set to 1 to enable real-time shadows."));

            // param sys_Illum
            AddParameter(
                new Texture2dParamter("sys_Illum", "sys_IllumSamp")
                .SetSRGBTexture(false)
                .SetEditable(false)
                .SetUserData("fragment")
                );

            // param deferredLightMultiplier
            AddParameter(
                new ScalarParameter("deferredLightMultiplier")
                .SetS(4.0f)
                .SetEditable(false)
                );

            AddParameter(
                new Vec3Parameter("deferredShadowColor")
                .SetX(0.25f)
                .SetY(0.25f)
                .SetZ(0.25f)
                );
        }

        public override string Name
        {
            get { return "DeferredLighting"; }
        }

        public override string Desc
        {
            get { return ""; }
        }

        public override Stage Stage
        {
            get { return Stage.Illumination; }
        }

        public override int UVChannelCount
        {
            get { return 0; }
        }

        public override void Code(StringBuilder b, string platform)
        {
            AddLine(b, "vec4 sys_Illum = tex2D(sys_IllumSamp, cReprojUV);");
            AddLine(b, "pipeline.Illumination += sys_Illum.rgb * deferredLightMultiplier;");
            AddLine(b, "#if DEFERREDLIGHTING_SHADOWS");
            AddLine(b, "pipeline.Illumination *= lerp(deferredShadowColor, vec3(1,1,1), sys_Illum.aaa);");
            AddLine(b, "#endif // DEFERREDLIGHTING_SHADOWS");
        }
    }
}
